package srcTA;

import java.util.List;

import lib.ArgumentValidator;

/**
 * Representation of a Bid
 * @author abhip
 *
 */
public class Bid implements Comparable<Bid>
{
    private int bidId;
    private int company;
    private double value;
    private List<Integer> regions;
    private double costPerRegion;
    private double rank;

    public Bid(int bidId, int company, double value, List<Integer> regions)
    {
        ArgumentValidator.IsGreaterThanOrEqualTo("bidId", bidId, 0);
        ArgumentValidator.IsGreaterThanOrEqualTo("company", company, 0);
        ArgumentValidator.IsGreaterThan("value", value, 0.0);
        ArgumentValidator.IsNotNull("regions", regions);

        this.bidId = bidId;
        this.company = company;
        this.value = value;
        this.regions = regions;
        this.costPerRegion = value/regions.size();
        this.rank = 0;
    }

    public int BidId()
    {
        return bidId;
    }
    
    /**
     * @return the company
     */
    public int Company()
    {
        return company;
    }
    
    @Override
    public int compareTo(Bid bid) 
    {
        if (this.bidId == bid.BidId())
        {
            return 0;
        }
        
        if (this.bidId < bid.BidId())
        {
            return -1;
        }
        
        return +1;
    }

    public double CostPerRegion()
    {
        return costPerRegion;
    }

    @Override
    public boolean equals(Object obj) 
    {
        if (this == obj)
            return true;
        
        if (obj == null)
            return false;
        
        if (getClass() != obj.getClass())
            return false;
        
        Bid other = (Bid) obj;
        if (bidId != other.bidId)
            return false;
        
        return true;
    }

    @Override
    public int hashCode() 
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + bidId;
        return result;
    }
    
    public double Rank()
    {
        return rank;
    }

    /**
     * @return the regions
     */
    public List<Integer> Regions()
    {
        return regions;
    }

    public void setRank(double rank) 
    {
        this.rank = rank;
    }

    @Override
    public String toString()
    {
        return String.format(
                "Bid [bidId=%d company=%s, value=%s, costPerRegion=%s, rank =%s, regions=%s]",
                bidId,
                company,
                value,
                costPerRegion,
                rank,
                regions.toString());
    }
    
    /**
     * @return the value
     */
    public double Value()
    {
        return value;
    }
}